﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Collections.ObjectModel;
using SPIWareMVVM.Views.Commands;

namespace SPIWareMVVM.ViewModels
{
    public class MaterialsViewModel : BaseViewModel
    {
        List<Part> _materials { get; set; }
        public ObservableCollection<Part> Materials
        {
            get
            {
                if (_materials == null) _materials = (from m in context.Parts select m).ToList();
                ObservableCollection<Part> list = _materials.ToObservableCollection();
                if (ApplicationData.SelectedCustomer != null) list = list.GetByCustomer(ApplicationData.SelectedCustomer);
                return list;
            }
            set { }
        }

        //public ObservableCollection<Part> ocMaterials { get { return ApplicationData.ocParts; } set { } }

        AddNewPartCommand _addNewPartCommand { get; set; }
        public AddNewPartCommand AddNewPartCommand
        {
            get
            {
                if (_addNewPartCommand == null) _addNewPartCommand = new AddNewPartCommand(this);
                return _addNewPartCommand;
            }
        }
    }
}
